use actix_web::{post, Responder, HttpResponse, web};
use crate::service::ktv_service::KtvService;
use crate::pojo::room::Room;
use crate::pojo::set_meal::SetMeal;
use crate::dao::RB;
use crate::pojo::freight_template::FreightTemplate;
use serde::{Deserialize, Serialize};
use crate::pojo::commodity_classification::CommodityClassification;
use crate::service::ktv_service;
use futures::executor;

// pub struct KtvController{
//     ktv_service : KtvService
// }
//
// pub async fn new_ktv_controller() -> KtvController{
//     KtvController{
//         ktv_service: ktv_service::new_ktv_service().await
//     }
// }

#[post("/query_ktv_info")]
pub async fn query_ktv_info() -> impl Responder {

    let result = ktv_service::new_ktv_service().await.find_all_ktv(&RB).await;
    HttpResponse::Ok().json( result)

}

#[post("/query_ktv_info_async")]
pub async fn query_ktv_info_async() -> impl Responder {

    let result = ktv_service::new_ktv_service().await.find_all_ktv_async(&RB).await;

    // let f = ktv_service::new_ktv_service().await.find_all_ktv_async(&RB);
    // executor::block_on(f);

    HttpResponse::Ok().json( result)

}

#[derive(Serialize, Deserialize)]
pub struct Info {
    good_id: String,
    user_id: String,
}

#[post("/get_freight")]
pub async fn get_freight(form: web::Form<Info>) -> impl Responder {

    let result = ktv_service::new_ktv_service().await.inquiry_of_postage(&RB, &form.good_id, &form.user_id).await;
    HttpResponse::Ok().json( result)
}

#[derive(Serialize, Deserialize)]
pub struct Classified{
    classification_id :String
}

// #[post("/get_classification")]
// pub async fn get_classification(form: web::Form<Classified>) -> impl Responder {
//
//     let result = KtvService{
//         room: Room {
//             id: None,
//             name: None,
//             ktv_id: None,
//             capacity: None,
//             remark: None,
//             create_time: None,
//             update_time: None,
//             version: None,
//             delete_flag: None,
//             set_meal_list: None
//         },
//         set_meal: SetMeal {
//             id: None,
//             room_id: None,
//             name: None,
//             singing_date: None,
//             time_frame: None,
//             time_interval: None,
//             begin_time: None,
//             finish_time: None,
//             remark: None,
//             create_time: None,
//             update_time: None,
//             version: None,
//             delete_flag: None,
//             start_time_list: None
//         },
//         freight_template: FreightTemplate {
//             id: None,
//             billing_rule: None,
//             province_id: None,
//             unified_price: None,
//             regional_price: None,
//             details: None,
//             create_time: None,
//             update_time: None,
//             delete_flag: None
//         },
//         commodity_classification: CommodityClassification {
//             id: None,
//             name: None,
//             parent_id: None,
//             remark: None,
//             create_time: None,
//             update_time: None,
//             delete_flag: None,
//             subcategory_list: None
//         }
//     }.query_classification(&RB, &form.classification_id).await;
//     HttpResponse::Ok().json( result)
// }



